package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.exception.LogincException;
import org.springframework.util.StringUtils;

import javax.security.auth.login.LoginException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AssertUtil {
    //判断指定value参数是否有值, 如果没有抛出异常, 信息: msg
    public static void isNull(String s,String msg) {
        if (!StringUtils.hasLength(s)) {
            throw new LogincException(msg);
        }

    }
    //判断两个值是否相等
    public static void isEquals(String s1, String s2, String msg) {

        if(s1 == null || s2 == null){
            throw new RuntimeException("传入参数不能为null");
        }

        if(!s1.equals(s2)){
            throw new LogincException(msg);
        }
    }

    public static boolean  isMobileNO(String phone) {
        boolean flag = false;
        try {

            Pattern p = Pattern.compile("^1\\d{10}$");

            Matcher m = p.matcher(phone);
            flag = m.matches();

        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
}
